
/**
*----------------------------------------------------------------------------------------
* Here defines all the functions generally used by all menu
*
*/

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val){
  
  return(parseFloat(val,10)==(val*1));
}

/**
* Set the background to yellow
*
* @param  String    thisObj
*
*/
function setYellow2(thisObj){
  
  thisObj.style.background= "yellow";
}

/**
* Set the background to white
*
* @param  String    thisObj
*
*/
function setWhite2(thisObj){
  
  thisObj.style.background= "white";
}

/**
* sync the val with 2 parameters take place
*
* @param  integer   srcObject
* @param  String    dstObject
*
*/
function syncVal2(srcObject, dstObject){
  
  srcObject = document.getElementsByName(srcObject);
  srcObject = srcObject[0];
  
  dstObject = document.getElementsByName(dstObject);
  dstObject = dstObject[0];
  
  /**
  * First check all the source and destinated value
  * That they are numeric and valid
  *
  */
  if(!isNumeric(srcObject.value)){
    
    srcObject.value = 0;
  }
  
  if(!isNumeric(dstObject.value)){
    
    dstObject.value = 0;
  }
  
  /**
  * Sync the val now
  *
  */
  dstObject.value = parseFloat(dstObject.value) - parseFloat(srcObject.value);
}

/**
* Sum the val with 2 parameters take place
*
* @param  integer   srcObject
* @param  String    dstObject
*
*/
function sumVal2(srcObject, dstObject){
  
  srcObject = document.getElementsByName(srcObject);
  srcObject = srcObject[0];
  
  dstObject = document.getElementsByName(dstObject);
  dstObject = dstObject[0];
  
  /**
  * First check all the source and destinated value
  * That they are numeric and valid
  *
  */
  if(!isNumeric(srcObject.value)){
    
    srcObject.value = 0;
  }
  
  if(!isNumeric(dstObject.value)){
    
    dstObject.value = 0;
  }
  
  /**
  * sum the val now
  *
  */
  dstObject.value = parseFloat(dstObject.value) + parseFloat(srcObject.value);
}